<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>公交管理系统</title>
    <link rel="stylesheet" href="../static/css/font-awesome-4.7.0/css/font-awesome.min.css" th:href="@{/css/font-awesome-4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" href="../static/css/style.css" th:href="@{/css/style.css}">
    <link rel="stylesheet" href="../static/layui/css/layui.css" th:href="@{/layui/css/layui.css}">
</head>
<body>
<div class="materialContainer">
    <!--登录-->
    <div class="box">
        <form method="post" class="layui-form" >
            <div class="title">登录</div>
            <div class="input">
                <label for="name">用户名</label>
                <input type="text" name="username" id="name">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="pass">密码</label>
                <input type="password" name="password" id="pass">
                <span class="spin"></span>
            </div>
            <div class="button login">
                <button lay-submit lay-filter="loginButton">
                    <span>登录</span>
                    <i class="fa fa-check"></i>
                </button>
            </div>
        </form>
    </div>
    <!--注册-->
    <div class="overbox">
        <form method="post" class="layui-form" >
            <div class="material-button alt-2">
                <span class="shape"></span>
            </div>
            <div class="title">注册</div>
            <div class="input">
                <label for="regname">用户名</label>
                <input type="text" name="username" id="regname">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="regpass">密码</label>
                <input type="password" name="password" id="regpass">
                <span class="spin"></span>
            </div>
            <div class="input">
                <label for="reregpass">确认密码</label>
                <input type="password" name="repeatPassword" id="reregpass">
                <span class="spin"></span>
            </div>
            <div class="button">
                <button lay-submit lay-filter="registerButton">
                    <span>注册</span>
                </button>
            </div>
        </form>
    </div>

</div>
<script src="../static/layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script src="../static/js/jquery.min.js" th:src="@{/js/jquery.min.js}"></script>
<script src="../static/js/index.js" th:src="@{/js/index.js}"></script>
<script>
    layui.use(['layer', 'form'], function(){
        var layer = layui.layer
            ,form = layui.form;
            $=layui.jquery

        /*登录表单提交*/
        form.on('submit(loginButton)',function (data) {
            // var maintenancePlace = JSON.stringify(data.field);获取表单数据
            $.ajax({
                type:"post",
                url:"/login/login",
                data:{username:data.field.username,password : data.field.password},
                dataType:"json",
                success : function (data) {
                    if (data.code === "200") {
                        window.location.href="/"
                    }else {
                        layer.msg(data.message,{icon:1,time:1000});
                    }
                }
            })
            return false;
        })
        /*注册表单提交*/
        form.on('submit(registerButton)',function (data) {
            // var maintenancePlace = JSON.stringify(data.field);
            $.ajax({
                type:"post",
                url:"/login/register",
                data:{username:data.field.username,password : data.field.password,repeatPassword: data.field.password},
                dataType:"json",
                success : function (data) {
                    if (data.code === "200") {
                        layer.msg(data.message,{icon:1,time:1000});
                    }else {
                        layer.msg(data.message,{icon:1,time:1000});
                    }
                }
            })
            return false;
        })
    });

</script>
</body>
</html>
